//
//  SMBaseViewCtrl.m
//  JiFengDaRen
//
//  Created by Lyc on 2017/8/30.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "UIButton+EnlargeTouchArea.h"
#import "SMBaseViewCtrl.h"

@interface SMBaseViewCtrl ()
{
    UIButton * _smBackButton;
}
@end

@implementation SMBaseViewCtrl

//
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleDefault;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navImage"] forBarMetrics:UIBarMetricsDefault];
//
    
   
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KBASEBGCOLOR;

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:__I6Width(18)]}];

    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(0, 0, 60, 39);
    [backButton setEnlargeEdgeWithTop:20 right:30 bottom:10 left:20];

    // 让按钮内部的所有内容左对齐
    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [backButton addTarget:self action:@selector(backClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    // 修改导航栏左边的item
    UIBarButtonItem *nagetiveSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    
    nagetiveSpace.width = __I6Width(-10);
    self.navigationItem.leftBarButtonItems = @[nagetiveSpace,backBarBtn];
    _smBackButton = backButton;

}

//调整navigationBar上控件的位置
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    if (@available(iOS 11.0, *)){
        _smBackButton.frame = CGRectMake(-12, 0, 60, 39);

    }
    
}

- (void)backClicked:(UIButton *)btn{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}



@end
